package com.znsb.msfq.fragment;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.mobstat.StatService;
import com.squareup.picasso.Picasso;
import com.znsb.msfq.BaseFragment;
import com.znsb.msfq.R;
import com.znsb.msfq.activity.FAQActivity;
import com.znsb.msfq.activity.FeedBackActivity;
import com.znsb.msfq.activity.HelpCenterActivity;
import com.znsb.msfq.activity.LoginActivity;
import com.znsb.msfq.activity.MyCollectActivity;
import com.znsb.msfq.activity.MyMessageActivity;
import com.znsb.msfq.activity.MyShowBillActivity;
import com.znsb.msfq.activity.PersonalDetailsActivity;
import com.znsb.msfq.activity.SetActivity;
import com.znsb.msfq.utils.IntentUtils;
import com.znsb.msfq.utils.SPUtils;
import com.znsb.msfq.utils.ValidateUtils;
import com.znsb.msfq.view.LoadingDialog;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 名称：我的
 * 创建时间：2016/10/20.
 * 作者：杨广
 * 手机号：17382373271
 * 说明：
 */

public class Home4Fragment extends BaseFragment {


    @Bind(R.id.home4_img_header)
    ImageView home4ImgHeader;
    @Bind(R.id.home4_tv_info)
    TextView home4TvInfo;
    @Bind(R.id.home4_img_arrow)
    ImageView home4ImgArrow;
    @Bind(R.id.home4_re_info)
    RelativeLayout home4ReInfo;
    @Bind(R.id.home4_re_layout1)
    RelativeLayout home4ReLayout1;
    @Bind(R.id.home4_re_layout2)
    RelativeLayout home4ReLayout2;
    @Bind(R.id.home4_re_layout3)
    RelativeLayout home4ReLayout3;
    @Bind(R.id.home4_re_layout4)
    RelativeLayout home4ReLayout4;
    @Bind(R.id.home4_re_layout5)
    RelativeLayout home4ReLayout5;
    @Bind(R.id.home4_re_layout6)
    RelativeLayout home4ReLayout6;
    @Bind(R.id.home4_re_layout7)
    RelativeLayout home4ReLayout7;

    @Override
    protected int getlayoutView() {
        return R.layout.frag_home4;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);
    }

    @Override
    public void onResume() {
        super.onResume();
        // 页面埋点
        StatService.onPageStart(getActivity(), "我的");
        /**
         * 登录前后的显示
         */
        if (!SPUtils.getIsLogin()) {
            home4TvInfo.setText("登录/注册");
            home4ImgArrow.setVisibility(View.INVISIBLE);
        } else {
            home4TvInfo.setText(ValidateUtils.getShowHint(SPUtils.getPhone(), 3, 8));
            home4ImgArrow.setVisibility(View.VISIBLE);
        }
        /**
         * 加载头像
         */
        Picasso.with(getActivity()).load(R.mipmap.my_headportrait_normal)
                .placeholder(R.mipmap.my_headportrait_normal)
                .error(R.mipmap.my_headportrait_normal)
                .into(home4ImgHeader);
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void clickListener(View view) {

    }


    @OnClick({R.id.home4_img_header, R.id.home4_re_info, R.id.home4_re_layout1, R.id.home4_re_layout2, R.id.home4_re_layout3, R.id.home4_re_layout4, R.id.home4_re_layout5, R.id.home4_re_layout6, R.id.home4_re_layout7})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.home4_img_header:
//                LoadingDialog dialog = new LoadingDialog(getActivity(), "加载中...");
//                dialog.show();
                break;
            case R.id.home4_re_info:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), PersonalDetailsActivity.class, null);
                break;
            case R.id.home4_re_layout1:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), MyShowBillActivity.class, null);
                break;
            case R.id.home4_re_layout2:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), MyCollectActivity.class, null);
                break;
            case R.id.home4_re_layout3:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), MyMessageActivity.class, null);
                break;
            case R.id.home4_re_layout4:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), FeedBackActivity.class, null);
                break;
            case R.id.home4_re_layout5:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), HelpCenterActivity.class, null);
                break;
            case R.id.home4_re_layout6:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), FAQActivity.class, null);
                break;
            case R.id.home4_re_layout7:
                if (!SPUtils.getIsLogin())
                    IntentUtils.startActivityAnimGeneral(getActivity(), LoginActivity.class, null);
                else
                    IntentUtils.startActivityAnimGeneral(getActivity(), SetActivity.class, null);
                break;
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        // 页面埋点
        StatService.onPageEnd(getActivity(), "我的");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
